package com.llap.exp190929.entity;

import lombok.Data;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.Date;

/**
 * Created by LLAP on 2019/10/14.
 * Copyright (c) 2019 LLAP. All rights reserved.
 */
@Entity
@Data
@DynamicInsert
@DynamicUpdate
public class TransactionRecord {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    @Column(precision = 11, scale = 2)
    private BigDecimal expense = null;
    @Column(precision = 11, scale = 2)
    private BigDecimal income = null;
    @Column(nullable = false, precision = 11, scale = 2)
    private BigDecimal balance;
    @Column
    private String transactionType;
    @Column
    private String remark;

    @Column(columnDefinition = "timestamp default CURRENT_TIMESTAMP", updatable = false)
    @Generated(GenerationTime.INSERT) private Date transactionDate = new Date();

    @ManyToOne(cascade = {CascadeType.MERGE, CascadeType.REFRESH}, optional = false, fetch = FetchType.EAGER)
    private CardAccount account = null;

    public TransactionRecord eraseCredential() {
        this.account.eraseCredential();
        return this;
    }
}
